local kuangyin = fk.CreateSkill{
    name = "ym2__kuangyin",
    tags = {Skill.Compulsory}
}
Fk:loadTranslationTable{
    ["ym2__kuangyin"] = "狂音",
    [":ym2__kuangyin"] = "锁定技，每当你使用即时牌后，展示一名角色一张手牌，若牌名不同，令之视为此牌，若相同，令其须使用之，然后令其发动〖苦肉〗。",
    ["#ym2__kuangyin"] = "狂音：展示一名角色一张手牌",
    ["#ym2__kuangyin-card"] = "狂音：展示 %dest 一张手牌，或点“取消”重新选择角色",
    ["@@ym2__kuangyin-inhand"] = "狂音",
    ["#ym2__kuangyin-use"] = "狂音：使用 %arg",
}
kuangyin:addEffect(fk.CardUseFinished,{
    can_trigger = function (self, event, target, player, data)
        return player == target and player:hasSkill(kuangyin.name) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players,function (tp)
            return tp:getHandcardNum() > 0
        end)
        while #targets > 0 do
            local tos = room:askToChoosePlayers(player,{
                targets = targets,
                skill_name = kuangyin.name,
                max_num = 1,
                min_num = 1,
                prompt = "#ym2__kuangyin",
                cancelable = true,
            })
            if #tos > 0 then
                local ids = {}
                local handcards = {}
                for _, id in ipairs(tos[1]:getCardIds("h")) do
                    if player:cardVisible(id) then
                        table.insert(handcards, id)
                    else
                        table.insert(ids, id)
                        table.insert(handcards, -114514)
                    end
                end
                local cards, result = room:askToChooseCardsAndChoice(player,{
                    cards = handcards,
                    choices = {"OK"},
                    max_num = 1,
                    min_num = 1,
                    skill_name = kuangyin.name,
                    prompt = "#ym2__kuangyin-card::"..tos[1].id,
                    cancel_choices = { "Cancel" }
                })
                if #cards > 0 and result ~= "Cancel" then
                    if cards[1] < 0 then
                        cards[1] = table.random(ids)
                    end
                    event:setCostData(self,{to = tos[1],card = cards[1]})
                    return true
                end
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).to
        local card = Fk:getCardById(event:getCostData(self).card)
        to:showCards(card)
        if card.trueName == data.card.trueName then
            if table.find(room.alive_players,function (tp)
                return to:canUseTo(card,tp,{bypass_times = true})
            end) then
                room:askToUseRealCard(to,{
                    pattern = tostring(Exppattern{id = {event:getCostData(self).card}}),
                    cancelable = false,
                    prompt = "#ym2__kuangyin-use:::"..card:toLogString(),
                    extra_data = {
                        bypass_times = true
                    }
                })
            end
            room:notifySkillInvoked(to,"kurou","drawcard")
            room:loseHp(to, 1, "kurou")
            if to:isAlive() then
                to:drawCards(2, "kurou")
            end
        else
            room:setCardMark(card,"@@ym2__kuangyin-inhand",data.card.trueName)
            Fk:filterCard(card.id)
        end
    end,
})
kuangyin:addEffect("filter",{
    global = true,
    card_filter = function(self, card, player)
        return card:getMark("@@ym2__kuangyin-inhand") ~= 0
    end,
    view_as = function (self, player, card)
        local to = Fk:cloneCard(card:getMark("@@ym2__kuangyin-inhand"),card.suit,card.number)
        return to
    end,
})
return kuangyin